import request from '../utils/request'
// import axios from 'axios'

// 登录
export const login = data=>{
  return request({
    method:'post',
    url:'/mp/v1_0/authorizations',
    data
  })
}
// 获取token
export const getUserProfile=()=>{
  // const user = JSON.parse(window.localStorage.getItem('user'))
  return request({
    method:'GET',
    url:'mp/v1_0/user/profile',
    // 登录 获取token  然后 复制接受过来的token 设置上去
    // headers:{
    //   // Authorization: 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NjA1NTgyMzgsInVzZXJfaWQiOjEsInJlZnJlc2giOmZhbHNlLCJ2ZXJpZmllZCI6dHJ1ZX0.hhUbgnV6juWo8D9ek1it0S82LaWrr9oIk7-EJqNDlqw'
    //   Authorization: `Bearer ${user.token}`
    // }
  })
}

// 获取文章列表
export const getUserArticle=(params)=>{
  return request({
    url:'/mp/v1_0/articles',
    method:'GET',
    params
  })
}

// 获取频道列表
export const getUserChannels=()=>{
  return request({
    url:'/mp/v1_0/channels',
    method:'GET'
  })
}

// 删除文章
export const deleteArticles=target=>{
  return request({
    url:`/mp/v1_0/articles/${target}`,
    method:'delete'
  })
}

// 新建文章
export const createArticle=(data,draft=false)=>{
  return request({
    url:'/mp/v1_0/articles',
    method:'post',
    params:{
      draft  //query使用params     false不为草稿  true为发表
    },
    // body使用  data传
    data
  })
}

// 编辑文章
export const updateArticle=(articleId,data,draft=false)=>{
  return request({
    url:`/mp/v1_0/articles/${articleId}`,
    method:'PUT',
    params:{
      draft
    },
    data
  })
}
// 获取指定文章
export const getArticle=articleId=>{
  return request({
    method:'GET',
    url:`/mp/v1_0/articles/${articleId}`
  })
}

//上传图片素材
export const uploadImage=data=>{
  return request({
    url:'/mp/v1_0/user/images',
    method:'POST',
    // 一半文件上传的接口请求头设置为Content-Type 为multipart/form-data
    //前提 axios不需要手动设置只要给data一个new FormData对象即可
    data
  })
}

